/*************************************************************************
	> File Name: 257.二叉树的所有路径_v2.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 三  9/15 13:02:27 2021
 ************************************************************************/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    //广搜
    typedef struct {
        TreeNode *node;
        string val;
    } Node;
    vector<string> binaryTreePaths(TreeNode* root) {
        vector<string> ans;
        queue<Node> que;

        que.push({root, to_string(root->val)});

        while (!que.empty()) {
            TreeNode *node = que.front().node;
            string path = que.front().val;
            que.pop();

            if (node->left == nullptr && node->right == nullptr) {
                ans.push_back(path);
            } else {
                if (node->left != nullptr) {
                    que.push({node->left, path + "->" + to_string(node->left->val)});
                } 
                if (node->right != nullptr) {
                    que.push({node->right, path + "->" + to_string(node->right->val)});
                }
            }
        }
        return ans;
    }
};
